package com.aokser.treeboot.controller;

import com.aokser.treeboot.entity.TreeNode;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by lenovo on 2016/12/15.
 */
@Controller
@RequestMapping(value = "/tree")
public class TreeController {

    @RequestMapping(value = "/index")
    public String index() {
        return "/index";
    }

    @ResponseBody
    @RequestMapping(value = "/data/{count}", method = RequestMethod.POST)
    public List<TreeNode> queryTreeNode(HttpServletRequest request, HttpServletResponse response,
                                        @PathVariable("count") Integer count) {
        List<TreeNode> nodes = new ArrayList<TreeNode>();
        if (null != count && count.intValue() > 0) {
            for (int i = 0; i < count; i++) {
                TreeNode node = new TreeNode(String.valueOf(i + 1), "节点" + (i + 1), false, true, "node_icon", null);
                nodes.add(node);
            }
        }

        return nodes;
    }

}
